package net.bxx2004.zephyr.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class CmdTask {
    private Process p;
    private String[] args;
    public CmdTask(String[] args){
        this.args = args;
    }
    public Process run(Consumer<String> result){
        try {
            p = Runtime.getRuntime().exec(args);
            String line = null;
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            while ((line = br.readLine()) != null) {
                result.accept(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return p;
    }
    public void stop(){
        p.destroy();
    }
}
